package rmi.farted;

import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

/** DisplayBox : to show some textual information
 *
 *  <p>Usage:
 *  <pre>
 *  DisplayBox story = new DisplayBox(this, "title-bar-message");
 *  story.append("some info ...");
 *  story.show();
 *  </pre>
 * 
 * @version 1.0, October 2010
 * @author J. Schoch
 */

public class DisplayBox extends Dialog {
	private static final long serialVersionUID = 1L;
	private Fertig schluss = null;
	private TextArea infoarea = null;

	/**
	 * @param f parent frame
	 * @param t title
	 */
	public DisplayBox(Frame f, String t) {
		super(f, false); // not editable
		this.setTitle(t);
		infoarea = new TextArea();
		infoarea.setBackground(new Color(200,230,230));
		infoarea.setEditable(false);
		infoarea.setFont(new Font("Serif",Font.ITALIC,16));
		this.add(infoarea,"Center");
		placeMeSomewhere();
		//this.pack();
		schluss = new Fertig(this); //get a Windows Adapter instance
	}

   private void placeMeSomewhere() {
      Random r = new Random();
      int x = (int) (600*r.nextFloat());
      int y = (int) (400*r.nextFloat());
      this.setBounds(x,y,300,300);
      }

   	/** set the display area background color
    * @param s text string
    */
   public void setScreen(Color c) {infoarea.setBackground(c);}

   /** clear the display area
    * @param s text string
    */
   	public void clear() {infoarea.setText("");}

   	/** add text to the display
   	 * @param s text string
   	 */
   	public void append(String s) {infoarea.append(s);}

   	/** add text to the display, issue also the "newline" character
   	 * @param s text string
   	 */
   	public void appendln(String s) {append(s); append("\n");}

   	/** add a separator line to the display
   	 */
   	public void appendSeparator() {
   		append("----------------------------------------------------\n");
   	}

   	//----- Window Adapter for the "closing" event
   	class Fertig extends WindowAdapter {
   		private Dialog d = null;
   		Fertig(Dialog d) {this.d = d; d.addWindowListener(this);}
   		public void windowClosing(WindowEvent e) {d.dispose();}
   	}

} // DisplayBox